#define _CRT_SECURE_NO_WARNINGS

#include "Queue.h"

void LevelOrder(BTNode* root)
{
	Queue* q = (Queue*)malloc(sizeof(Queue));
	QueueInit(q);

	if (root)
		QueuePush(q, root);

	while (!QueueEmpty(q))
	{
		BTNode* front = QueueFront(q);
		QueuePop(q);

		printf("%c ", front->data);
		if (front->left)
			QueuePush(q, front->left);
		if (front->right)
			QueuePush(q, front->right);
	}

	printf("\n");

	free(q);
}

BTNode* BuyBTNode(BTNodeDataType val)
{
	BTNode* newNode = (BTNode*)malloc(sizeof(BTNode));
	if (NULL == newNode)
	{
		perror("malloc");
		exit(-1);
	}

	newNode->left = NULL;
	newNode->right = NULL;
	newNode->data = val;

	return newNode;
}

int main()
{
	BTNode* A = BuyBTNode('A');
	BTNode* B = BuyBTNode('B');
	BTNode* C = BuyBTNode('C');
	BTNode* D = BuyBTNode('D');
	BTNode* E = BuyBTNode('E');
	BTNode* F = BuyBTNode('F');

	A->left = B;
	A->right = C;
	B->left = D;
	B->right = E;
	C->right = F;

	LevelOrder(A);

	return 0;
}

